package user

import grails.test.GrailsUnitTestCase
import java.util.Date;

import user.Tutor;

class TutorTests extends GrailsUnitTestCase {
	
	private String NAME_1 = "João"
	private String SOBRENOME_1 = "Silva"
	private String LOGIN_1 = "joaosilva12"
	private String PASSWORD_1 = "abc123"
	private String EMAIL_1 = "joaosilva12@dsc.ufcg.edu.br"
	private Date ADMISSION_1 = new Date()
	private String TITULACAO_1 = "Doutor"
	
	
	protected void setUp() {
		super.setUp()
	}
	
	protected void tearDown() {
		super.tearDown()
	}
	
	void testValues() {
		Tutor t = new Tutor(nome:NAME_1, sobrenome:SOBRENOME_1, login:LOGIN_1,
		password:PASSWORD_1, email:EMAIL_1, admission:ADMISSION_1)
		assertEquals NAME_1, t.nome
		assertEquals SOBRENOME_1, t.sobrenome
		assertEquals LOGIN_1, t.login
		assertEquals PASSWORD_1, t.password
		assertEquals EMAIL_1, t.email
		assertEquals ADMISSION_1, t.admission
	}
	
	
	void testConstraints(){
		def t = new Tutor(nome:NAME_1, sobrenome:SOBRENOME_1, login:LOGIN_1,
		password:PASSWORD_1, email:EMAIL_1, admission:ADMISSION_1, titulacao:TITULACAO_1)
		
		mockForConstraintsTests(Tutor,[t])
		assertTrue t.validate()
	
		print t.errors
 
		def t2 = new Tutor(nome:NAME_1, sobrenome:SOBRENOME_1, login:LOGIN_1,
		password:PASSWORD_1, email:EMAIL_1, admission:ADMISSION_1, titulacao:TITULACAO_1)
	
		assertFalse t2.validate() 
		assertEquals "unique", t2.errors["login"]
		assertEquals "unique", t2.errors["email"]

		t = new Tutor()

		assertFalse t.validate() 
		assertEquals "nullable", t.errors["nome"] 
		assertEquals "nullable", t.errors["sobrenome"]
		assertEquals "nullable", t.errors["login"]
		assertEquals "nullable", t.errors["password"]
		assertEquals "nullable", t.errors["email"]
		assertEquals "nullable", t.errors["admission"]
		assertEquals "nullable", t.errors["titulacao"]

	}
}
